package com.guli.vod.controller;

import com.aliyuncs.exceptions.ClientException;
import com.guli.commonUtils.R;
import com.guli.vod.service.impl.VodServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author zxc
 * @date 2023/04/08 17:11
 **/
@Api(description = "上传音视频到阿里云")
@RestController
@RequestMapping("/edu/videoVod")
@ResponseBody
//@CrossOrigin // 解决跨域问题;
public class VodController {
    @Autowired
    private VodServiceImpl vodService;


    @ApiOperation(value = "上传音视频文件")
    @PostMapping("uploadVideo")
    public R uploadVideoVod(
            @ApiParam(name = "file" , value = "音视频文件" ,required = true)
            MultipartFile file){
        String videoId = vodService.uploadVideo(file);
        return R.ok().data("videoId" , videoId);
    }

    @ApiOperation(value = "删除音视频文件")
    @DeleteMapping("deleteVideo/{videoSourceId}")
    public R deleteVideoVod(
            @ApiParam(name = "videoSourceId" , value = "云端音视频id" , required = true)
            @PathVariable String videoSourceId){
        vodService.deleteVideoVod(videoSourceId);
        return R.ok();
    }

    @ApiOperation(value = "删除若干个音视频文件")
    @DeleteMapping("deleteVideos")
    public R deleteVideoVodByIds(
            @ApiParam(name = "videoSourceIds" , value = "云端音视频id集合" , required = true)
            @RequestBody List<String> videoSourceIds){
        vodService.deleteVideoVodByIds(videoSourceIds);
        return R.ok();
    }
}
